
var Waterline = require('waterline');
var uuid = require('node-uuid');
var moment = require('moment');

/**
 * 知识库子栏目
 */
module.exports = Waterline.Collection.extend({
    identity: 'knowledgegroup',
    tableName: 'tb_knowledge_group',
    connection: "mysql",
    attributes: {

        rowId: {
            type: 'string',
            primaryKey: true,
            unique: true,
            required: true,
            uuidv4: true,
            columnName: 'rowid',
            defaultsTo: function () {
                return uuid.v4();
            }
        },
        parentId: {
            type: 'string',
            columnName: 'parentid'
        },
        name: {
            type: 'string',
            required: true,
            columnName: 'name'
        },
        centers: {
            collection: 'knowledgecenter',
            via: 'knowledgegroup'
        },
        // parentCenters: {
        //     collection: 'knowledgecenter',
        //     via: 'fileType'
        // },
        createUid: {
            type: 'string',
            required: true,
            columnName: 'createuid',
            model: 'user'
        },
        /**
         *是否删除，1表示正常默认为1，0表示删除
         */
        enable: {
            type: 'string',
            columnName: 'enable',
            defaultsTo:'1'
        },

        toJSON: function () {
            var obj = this.toObject();
            obj.createdAt = moment(obj.createdAt).format('YYYY/MM/DD hh:mm');
            obj.updatedAt = moment(obj.updatedAt).format('YYYY/MM/DD hh:mm');
            return obj;
        }

    }
});
